﻿/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#ifndef MK_SYSTEM_STATE_H
#define MK_SYSTEM_STATE_H
#include "MkUtil/MkTypes.h"
#include "MkTime.h"

class MkApi CSystemState
{
    typedef struct _system_state
    {
        Uint64 User;
        Uint64 Nice;
        Uint64 Sys;
        Uint64 Idle;
        Uint64 IoWait;
        Uint64 Irq;
        Uint64 SoftIrq;
        Uint64 Steal;
        Uint64 Guest;
        Uint64 TotalJiffies()
        {
            return User + Nice + Sys + Idle + IoWait + Irq + SoftIrq + Steal + Guest;
        }
        Uint64 WorkJiffies()
        {
            return User + Nice + Sys;
        }
    } MkSystemState;
public:
    CSystemState();
    ~CSystemState();

    Uint32 Update();

    MkString GetSelfStartTime();
    MkString GetSystemStartTime();
    double GetSystemCpuPercent();
    double GetSystemMemPercent();

protected:
private:
    Uint32 UpdateMemInfo();
    Uint32 GetLinuxVersion();
    Uint32 GetCpuInfo();
    Uint32 GetState();
private:
    CMkTime         m_StartTime;
    CMkTime         m_SystemStartTime;
    double           m_SystemCpuPercent;
    double           m_SystemMemPercent;

    MkString        m_LinuxVersion;
    MkString        m_Version;

    Uint32          m_CpuCores;
    MkString        m_CpuModelName;

    MkSystemState   m_LastSystemState;
};


#endif
